﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InSafetyAirClient.GUI.Plane
{
    public partial class ListP : UserControl
    {
        List<InSafetyAirClient.InSafetyAirService.Plane> planes = null;
        List<InSafetyAirClient.InSafetyAirService.PlaneModel> models = null;
        AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection();

        public ListP()
        {
            InitializeComponent();
        }

        private void ListP_Load(object sender, EventArgs e)
        {
            if (!this.DesignMode)
            {
                DataTable dataTable1 = new DataTable();
                dataTable1.Columns.Add("Plane Model", typeof(string));
                dataTable1.Columns.Add("Registration Number", typeof(string));
                ServiceSingle servS = ServiceSingle.Instance;
                planes = servS.getService().GetAll(typeof(InSafetyAirClient.InSafetyAirService.Plane).Name).OfType<InSafetyAirClient.InSafetyAirService.Plane>().ToList();
                models = servS.getService().GetAll(typeof(InSafetyAirClient.InSafetyAirService.PlaneModel).Name).OfType<InSafetyAirClient.InSafetyAirService.PlaneModel>().ToList();
                foreach (InSafetyAirService.Plane plane in planes)
                {
                    foreach (InSafetyAirService.PlaneModel planeModel in models)
                    {
                        if(planeModel.planeModelId==plane.planeModelId)
                            dataTable1.Rows.Add(planeModel.planeModelName, plane.registrationNo);
                    }
                }
                dataGridView1.DataSource = dataTable1;
            }
        }

    }
}
